All Questions
68 questions
1vote
3answers
125views
sed to replace in a file, with both old and new strings in files
I want to automatically comment out a code block in PHP file, as below: The original block: // Enable all errors ini_set('display_startup_errors', 1); ini_set('display_errors', 1); ...
-3votes
2answers
97views
How can find special row and replace special strings
I wrote a todo list script with "add","clear" and "find" argument. I need to pass a "done" argument and script find related row and replace its first column ...
0votes
1answer
211views
Add one second to yyyymmddhhmmss with awk
I have this file where the seventh field is a yyyymmddhhmmss. I need to increase just one second this number. So far, I've come up with: awk 'BEGIN{FS=OFS="|"} $7=$7+1 ' <file> And ...
2votes
2answers
818views
Delete multiline blocks with sed non-greedy
How can one remove code blocks starting with /** START */ and ending with /** END */ using sed non-greedily considering that code blocks are multiline and empty lines may occur within START-END blocks?...
0votes
2answers
291views
insert block of lines only before first matched pattern
i need to insert the below lines (after variable substitution) before the first matched string which is server { in /etc/nginx/nginx.conf Variable: website=www.hello.com Block of lines: server { # ...
0votes
1answer
2kviews
Include spaces and tabs in "awk" search and replace
Another user helped me earlier to fix something I'm doing with awk, where I search for a string at any point in all files and replace two numbers in the same line when I find it. awk -i inplace '/^...
1vote
2answers
850views
awk get column value from file 2 for file 1 if value matches in 2 columns [duplicate]
I have 2 files, trying to set column value that is taken from file2 into file1 when their columns match file1: signup||20200620|A3332|en|LA||ACTIVE signup||20200620|B4443|en|CA|66001|ACTIVE signup||...
-1votes
2answers
178views
awk bring same field value from file1 and set in file2 [closed]
File1 (parent) 2210 1110 Earth 2211 1111 Marse 2212 1112 Saturn 2213 1113 Pluto File2 (child) 3310 2210 Earth 3311 2210 Space 3312 2211 Mars 3313 2211 Space 3314 2212 Saturn 3315 2212 Space 3316 ...
-1votes
3answers
499views
awk print only modified lines
I have file like this d1000 1000 d1001 100 d1002 10 d1003 1 I want to modify second column where length is not equal 4. But I want to print only lines that are modified, so original text in column 2 ...
0votes
2answers
238views
sed and awk in sh script not replacing text
The desired work to find a string, and replace to another (all occurrencies), and rewrite/update the file too. The file is an pbxproj file. I linked a sample of this file sample of the file (please ...
1vote
3answers
999views
Modify and Replace $1 (awk) or \1 (sed) Values from Decimal to Hexadecimal Globally in a String?
Is it possible to Modify and Replace $1 (awk) or \1 (sed) Values from Decimal to Hexadecimal Globally in a String? It is possible that the string may contain any decimal value, which needs to be ...
-1votes
4answers
534views
How to replace a part of the word using sed command
I have a file with just one word in each line. I want to delete some part of the word in each line. How can I delete that part using sed command? Ex: u_fox/u_snake/u_snail/u_plus/u_core/u_vector/...
0votes
3answers
229views
Replace specific lines of a file with values of other file
I would like to replace the 2nd, 6th, and 7th rows of file1 with the values in each row of file2 and generate a series of files equal to wc -l file2 cat file1 w 3 y G 7 1.2 Q cat file2 1 1 ...
0votes
1answer
688views
If a sum equals zero how can I get awk to print another known value to the file
I have a numerous files in which I extract the total number of records and total number of missing files in order to compute data averages. I have numerous files where the number of missing records ...
-1votes
5answers
2kviews
Replace characters on specific lines and specific columns
Consider this sample.txt: ATO N X B AT H1 X BT ATOM H25 X BAA ATOM H3 X BUTZ ATOM CA X BAT I want to replace X's from lines 2-4, ...